#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_set>

using namespace std;

int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
    unordered_set<string> hash(wordList.begin(), wordList.end());
    unordered_set<string> vis;
    queue<string> q;
    int ret = 1;

    if ((beginWord == endWord) || (hash.count(endWord) == 0))
        return 0;

    q.push(beginWord);
    vis.insert(beginWord);

    while (!q.empty())
    {
        int size = q.size();
        ++ret;
        while (size--)
        {
            string tmp = q.front();
            q.pop();
            for (int i = 0; i < tmp.size(); ++i)
            {
                string t = tmp;
                for (int j = 'a'; j <= 'z'; ++j)
                {
                    t[i] = j;
                    if (hash.count(t) && !vis.count(t))
                    {
                        if (t == endWord)
                            return ret;

                        q.push(t);
                        vis.insert(t);
                    }
                }
            }
        }
    }

    return 0;
}

int main()
{

	return 0;
}